/*******************************************************************************
*
*  (C) COPYRIGHT AUTHORS, 2022 - 2023
*
*  TITLE:       DBK.H
*
*  VERSION:     1.40
*
*  DATE:        20 Oct 2023
*
*  Cheat Engine's DBK driver interface header.
*
* THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
* ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED
* TO THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
* PARTICULAR PURPOSE.
*
*******************************************************************************/

#pragma once

//
// Cheat Engine's DBK driver interface.
//

#define DBK_DEVICE_TYPE (DWORD)FILE_DEVICE_UNKNOWN

#define DBK_FUNC_OPEN_PROCESS (DWORD)0x0802
#define DBK_FUNC_ALLOCATEMEM_NONPAGED (DWORD)0x0826
#define DBK_FUNC_FREEMEM (DWORD)0x084C
#define DBK_FUNC_MAP_MEMORY (DWORD)0x084D
#define DBK_FUNC_UNMAP_MEMORY (DWORD)0x084E
#define DBK_FUNC_EXECUTE_CODE (DWORD)0x083C

#define	IOCTL_CE_ALLOCATEMEM_NONPAGED    \
    CTL_CODE(DBK_DEVICE_TYPE, DBK_FUNC_ALLOCATEMEM_NONPAGED, METHOD_BUFFERED, FILE_READ_ACCESS | FILE_WRITE_ACCESS)

#define	IOCTL_CE_FREEMEM    \
    CTL_CODE(DBK_DEVICE_TYPE, DBK_FUNC_FREEMEM, METHOD_BUFFERED, FILE_READ_ACCESS | FILE_WRITE_ACCESS)

#define IOCTL_CE_MAP_MEMORY    \
    CTL_CODE(DBK_DEVICE_TYPE, DBK_FUNC_MAP_MEMORY, METHOD_BUFFERED, FILE_READ_ACCESS | FILE_WRITE_ACCESS)

#define IOCTL_CE_UNMAP_MEMORY    \
    CTL_CODE(DBK_DEVICE_TYPE, DBK_FUNC_UNMAP_MEMORY, METHOD_BUFFERED, FILE_READ_ACCESS | FILE_WRITE_ACCESS)

#define IOCTL_CE_EXECUTE_CODE    \
    CTL_CODE(DBK_DEVICE_TYPE, DBK_FUNC_EXECUTE_CODE, METHOD_BUFFERED, FILE_READ_ACCESS | FILE_WRITE_ACCESS)

#define IOCTL_CE_OPENPROCESS     \
    CTL_CODE(DBK_DEVICE_TYPE, DBK_FUNC_OPEN_PROCESS, METHOD_BUFFERED, FILE_READ_ACCESS | FILE_WRITE_ACCESS)


BOOL DbkStartVulnerableDriver(
    _In_ KDU_CONTEXT* Context);

BOOL DbkMapDriver(
    _In_ PKDU_CONTEXT Context,
    _In_ PVOID ImageBase);

BOOL DbkControlDSE(
    _In_ PKDU_CONTEXT Context,
    _In_ ULONG DSEValue,
    _In_ ULONG_PTR Address);

BOOL WINAPI DbkOpenProcess(
    _In_ HANDLE DeviceHandle,
    _In_ HANDLE ProcessId,
    _In_ ACCESS_MASK DesiredAccess,
    _Out_ PHANDLE ProcessHandle);
